package com.sgb.kjwl.view.widget;

import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.alibaba.android.arouter.launcher.ARouter;
import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.CarInfo;
import com.sgb.kjwl.model.entity.UserMsgEntity;
import com.swgk.core.util.ACAdminDialogUtils;
import com.sgb.kjwl.view.ui.activity.self.carMaster.BusinessOpportunitySubscriptionActivity;
import com.sgb.kjwl.view.ui.activity.self.logistics.CarriageBusinessActivity;
import com.sgb.kjwl.view.ui.activity.self.logistics.PublishCargoActivity;
import com.sgb.link.router.PathLogistics;
import com.swgk.core.dialog.BaseBottomDialog;
import com.swgk.core.dialog.DialogViewHolder;

import java.util.List;

import static com.swgk.core.util.ACAdminDialogUtils.MK_10_CHENGYUNSHANGJI;
import static com.swgk.core.util.ACAdminDialogUtils.MK_10_HUOYUANGUANLI;

/**
 * 商机选择底部坦克
 */
public class SjSelectDialog extends BaseBottomDialog {
    private String managerAuth = "";
    private String driverAuth = "";
    TextView tvCancel;
    TextView tvSj;
    TextView tvSj1;
    DialogClickCallBack clickCallBack;
    int type;
    private List<CarInfo> carInfo;

    public List<CarInfo> getCarInfo() {
        return carInfo;
    }

    public void setCarInfo(List<CarInfo> carInfo) {
        this.carInfo = carInfo;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
        if (type == 1) {
            tvSj.setText("发布货源");
            tvSj1.setText("发布承运");
        }
    }

    public SjSelectDialog(Context context, UserMsgEntity data, DialogCallBack dialogCallBack) {
        super(context, dialogCallBack);
        managerAuth = data.isRelevance() ? "SUCCESS" : "NONE";
        driverAuth = data.isDriverAuth() ? "SUCCESS" : "NONE";

    }

    public DialogClickCallBack getClickCallBack() {
        return clickCallBack;
    }

    public void setClickCallBack(DialogClickCallBack clickCallBack) {
        this.clickCallBack = clickCallBack;
    }

    @Override
    protected int dialogLayout() {
        return R.layout.dailog_select_sj_type;
    }

    @Override
    protected void initView(DialogViewHolder holder, Bundle savedInstanceState) {
        tvCancel = holder.getDialog().findViewById(R.id.tv_cancel);
        tvSj = holder.getDialog().findViewById(R.id.tv_cy);
        tvSj1 = holder.getDialog().findViewById(R.id.tv_fb);

        tvCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
        tvSj.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //承运商机
                if (type == 1) {
                    if (ACAdminDialogUtils.isPermission(MK_10_HUOYUANGUANLI, false) == ACAdminDialogUtils.TYPE_NO_PERMISSION) {
                        ACAdminDialogUtils.showACDialog(ACAdminDialogUtils.TYPE_NO_PERMISSION, context);
                    } else {
                        PublishCargoActivity.start(context);
                    }
                } else {
                    if (ACAdminDialogUtils.isPermission(MK_10_CHENGYUNSHANGJI, false) == ACAdminDialogUtils.TYPE_NO_PERMISSION) {
                        ACAdminDialogUtils.showACDialog(ACAdminDialogUtils.TYPE_NO_PERMISSION, context);
                    } else {
                        CarriageBusinessActivity.start(context);
                    }
                }
                dismiss();
            }
        });
        tvSj1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (driverAuth.equals("SUCCESS")) {
                    //司机
                    if (type == 1) {
                        if (carInfo != null && carInfo.size() > 0) {
                            ARouter.getInstance().build(PathLogistics.CarriagePushActivity).navigation();
                        } else {
                            if (clickCallBack != null) {
                                clickCallBack.dialogContent("nocar");
                            }
                        }
                    } else {
                        BusinessOpportunitySubscriptionActivity.start(context);
                    }
                } else {
                    if (!driverAuth.equals("") && clickCallBack != null) {
                        switch (driverAuth) {
                            case "FAIL":
                                clickCallBack.dialogContent("driverFail");
                                break;
                            case "STANDBY":
                                clickCallBack.dialogContent("driverStandby");

                                break;
                            default:
                                clickCallBack.dialogContent("driver");
                                break;
                        }
                    }
                }
                dismiss();
            }
        });
    }

    public interface DialogClickCallBack {
        void dialogContent(String content);
    }
}
